package com.czk.model.proxy.dynamincproxy.practice3;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Author:ChenZhangKun
 * @Date: 2022/8/25 14:03
 */
public class WorkHandler implements InvocationHandler {
    private Object target;

    public WorkHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (method.getName().equals("work")) {
            System.out.println("代理前");
            Object invoke = method.invoke(target, args);
            System.out.println("代理后");
            return invoke;
        }
        // 放行
        return method.invoke(target, args);
    }
}
